package demo;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by liuteng on 2015/12/26.
 */
public class Demo {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException {
        String fileName = "D:\\ideaWorkspace\\blend\\src\\main\\resources\\novel\\out\\jpnx";
        int index = 1;
        int count = 0;
        String ext = ".txt";
        File file = new File("D:\\ideaWorkspace\\blend\\src\\main\\resources\\novel\\jpnx.txt");
        FileReader fr = new FileReader(file);
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "GBK"));
        String currb = br.readLine();
        int sizeP = 10000;
        BufferedWriter bw = null;
        while (currb != null) {
            if (count % sizeP == 0) {
                if (bw != null) {
                    bw.flush();
                }
                bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(fileName + index + ext)), "UTF-8"));
                index++;
            }
            bw.write(currb);
            bw.newLine();
            currb = br.readLine();
            count++;
        }
        if (bw != null) {
            bw.flush();
        }
    }
}
